package dataStructureAlgorithms.binaryTree;

/**
 * @description: TODO 二叉树
 * @author: wzj
 * @create: 2019/5/17 9:11
 */
public class BinaryTree {
    private Node root;

    public BinaryTree() {
    }

    public BinaryTree(Node root) {
        this.root = root;
    }

    /**
     * 先序遍历树
     * @param node
     */
    public void preorderTraversal(Node node){
        if(node!=null){
            System.out.print(node.getData()+" ");
            preorderTraversal(node.getLeftNode());
            preorderTraversal(node.getRightNode());
        }
    }

    /**
     * 中序遍历树
     * @param node
     */
    public void inorderTraversal(Node node){
        if(node!=null){
            inorderTraversal(node.getLeftNode());
            System.out.print(node.getData()+" ");
            inorderTraversal(node.getRightNode());
        }
    }

    /**
     * 中序遍历树
     * @param node
     */
    public void postorderTraversal(Node node){
        if(node!=null){
            postorderTraversal(node.getLeftNode());
            postorderTraversal(node.getRightNode());
            System.out.print(node.getData()+" ");
        }
    }
}
